00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef TINYXML_INCLUDED
00027 #define TINYXML_INCLUDED
00028
00029 #ifdef _MSC_VER
00030 #pragma warning( disable : 4530 )
00031 #pragma warning( disable : 4786 )
00032 #endif
00033
00034 #include <ctype.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <assert.h>
00039
00040
00041 #if defined( _DEBUG ) && !defined( DEBUG )
00042 #define DEBUG
00043 #endif
00044
00045 #if defined( DEBUG ) && defined( _MSC_VER )
00046 #include <windows.h>
00047 #define TIXML_LOG OutputDebugString
00048 #else
00049 #define TIXML_LOG printf
00050 #endif
00051
00052 #ifdef TIXML_USE_STL
00053 #include <string>
00054 #include <iostream>
00055
00056 #define TIXML_STRING std::string
00057 #define TIXML_ISTREAM std::istream
00058 #define TIXML_OSTREAM std::ostream
00059 #else
00060 #include "tinystr.h"
00061 #define TIXML_STRING TiXmlString
00062 #define TIXML_OSTREAM TiXmlOutStream
00063 #endif
00064
00065 class TiXmlDocument;
00066 class TiXmlElement;
00067 class TiXmlComment;
00068 class TiXmlUnknown;
00069 class TiXmlAttribute;
00070 class TiXmlText;
00071 class TiXmlDeclaration;
00072
00073 class TiXmlParsingData;
00074
00075
00076
00077
00078 struct TiXmlCursor
00079 {
00080 TiXmlCursor() { Clear(); }
00081 void Clear() { row = col = -1; }
00082
00083 int row;
00084 int col;
00085 };
00086
00087
00088
00089 enum
00090 {
00091 TIXML_SUCCESS,
00092 TIXML_NO_ATTRIBUTE,
00093 TIXML_WRONG_TYPE
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 class TiXmlBase
00119 {
00120 friend class TiXmlNode;
00121 friend class TiXmlElement;
00122 friend class TiXmlDocument;
00123
00124 public:
00125 TiXmlBase() {}
00126 virtual ~TiXmlBase() {}
00127
00128
00129
00130
00131
00132
00133 virtual void Print( FILE* cfile, int depth ) const = 0;
00134
00135
00136
00137
00138
00139
00140
00141 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00142
00143
00144 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 int Row() const { return location.row + 1; }
00165 int Column() const { return location.col + 1; }
00166
00167 protected:
00168
00169
00170 class StringToBuffer
00171 {
00172 public:
00173 StringToBuffer( const TIXML_STRING& str );
00174 ~StringToBuffer();
00175 char* buffer;
00176 };
00177
00178 static const char* SkipWhiteSpace( const char* );
00179 inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); }
00180
00181 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00182
00183 #ifdef TIXML_USE_STL
00184 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00185 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00186 #endif
00187
00188
00189
00190
00191
00192 static const char* ReadName( const char* p, TIXML_STRING* name );
00193
00194
00195
00196
00197 static const char* ReadText( const char* in,
00198 TIXML_STRING* text,
00199 bool ignoreWhiteSpace,
00200 const char* endTag,
00201 bool ignoreCase );
00202
00203 virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
00204
00205
00206 static const char* GetEntity( const char* in, char* value );
00207
00208
00209 inline static const char* GetChar( const char* p, char* _value )
00210 {
00211 assert( p );
00212 if ( *p == '&' )
00213 {
00214 return GetEntity( p, _value );
00215 }
00216 else
00217 {
00218 *_value = *p;
00219 return p+1;
00220 }
00221 }
00222
00223
00224
00225 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00226
00227 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00228
00229
00230 static bool StringEqual( const char* p,
00231 const char* endTag,
00232 bool ignoreCase );
00233
00234
00235 enum
00236 {
00237 TIXML_NO_ERROR = 0,
00238 TIXML_ERROR,
00239 TIXML_ERROR_OPENING_FILE,
00240 TIXML_ERROR_OUT_OF_MEMORY,
00241 TIXML_ERROR_PARSING_ELEMENT,
00242 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00243 TIXML_ERROR_READING_ELEMENT_VALUE,
00244 TIXML_ERROR_READING_ATTRIBUTES,
00245 TIXML_ERROR_PARSING_EMPTY,
00246 TIXML_ERROR_READING_END_TAG,
00247 TIXML_ERROR_PARSING_UNKNOWN,
00248 TIXML_ERROR_PARSING_COMMENT,
00249 TIXML_ERROR_PARSING_DECLARATION,
00250 TIXML_ERROR_DOCUMENT_EMPTY,
00251
00252 TIXML_ERROR_STRING_COUNT
00253 };
00254 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00255
00256 TiXmlCursor location;
00257
00258 private:
00259 struct Entity
00260 {
00261 const char* str;
00262 unsigned int strLength;
00263 char chr;
00264 };
00265 enum
00266 {
00267 NUM_ENTITY = 5,
00268 MAX_ENTITY_LENGTH = 6
00269
00270 };
00271 static Entity entity[ NUM_ENTITY ];
00272 static bool condenseWhiteSpace;
00273 };
00274
00275
00276
00277
00278
00279
00280
00281
00282 class TiXmlNode : public TiXmlBase
00283 {
00284 friend class TiXmlDocument;
00285 friend class TiXmlElement;
00286
00287 public:
00288 #ifdef TIXML_USE_STL
00289
00290
00291
00292
00293 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00312
00313
00314 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00315
00316 #else
00317
00318 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00319 #endif
00320
00321
00322
00323
00324 enum NodeType
00325 {
00326 DOCUMENT,
00327 ELEMENT,
00328 COMMENT,
00329 UNKNOWN,
00330 TEXT,
00331 DECLARATION,
00332 TYPECOUNT
00333 };
00334
00335 virtual ~TiXmlNode();
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 const char * Value() const { return value.c_str (); }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 void SetValue(const char * _value) { value = _value;}
00361
00362 #ifdef TIXML_USE_STL
00363
00364 void SetValue( const std::string& _value )
00365 {
00366 StringToBuffer buf( _value );
00367 SetValue( buf.buffer ? buf.buffer : "" );
00368 }
00369 #endif
00370
00371
00372 void Clear();
00373
00374
00375 TiXmlNode* Parent() const { return parent; }
00376
00377 TiXmlNode* FirstChild() const { return firstChild; }
00378 TiXmlNode* FirstChild( const char * value ) const;
00379
00380 TiXmlNode* LastChild() const { return lastChild; }
00381 TiXmlNode* LastChild( const char * value ) const;
00382
00383 #ifdef TIXML_USE_STL
00384 TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00385 TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00386 #endif
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00405
00406
00407 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00408
00409 #ifdef TIXML_USE_STL
00410 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00411 #endif
00412
00413
00414
00415
00416 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00429 TiXmlNode* LinkAfterChild( TiXmlNode* afterThis, TiXmlNode* addThis );
00430
00431
00432
00433
00434 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00435
00436
00437
00438
00439 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00440
00441
00442
00443
00444 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00445
00446
00447 bool RemoveChild( TiXmlNode* removeThis );
00448
00449
00450 TiXmlNode* PreviousSibling() const { return prev; }
00451
00452
00453 TiXmlNode* PreviousSibling( const char * ) const;
00454
00455 #ifdef TIXML_USE_STL
00456 TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00457 TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00458 #endif
00459
00460
00461 TiXmlNode* NextSibling() const { return next; }
00462
00463
00464 TiXmlNode* NextSibling( const char * ) const;
00465
00466
00467
00468
00469
00470 TiXmlElement* NextSiblingElement() const;
00471
00472
00473
00474
00475
00476 TiXmlElement* NextSiblingElement( const char * ) const;
00477
00478 #ifdef TIXML_USE_STL
00479 TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00480 #endif
00481
00482
00483 TiXmlElement* FirstChildElement() const;
00484
00485
00486 TiXmlElement* FirstChildElement( const char * value ) const;
00487
00488 #ifdef TIXML_USE_STL
00489 TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00490 #endif
00491
00492
00493
00494
00495
00496 virtual int Type() const { return type; }
00497
00498
00499
00500
00501 TiXmlDocument* GetDocument() const;
00502
00503
00504 bool NoChildren() const { return !firstChild; }
00505
00506 TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00507 TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00508 TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00509 TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00510 TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00511 TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00512
00513 virtual TiXmlNode* Clone() const = 0;
00514
00515 void SetUserData( void* user ) { userData = user; }
00516 void* GetUserData() { return userData; }
00517
00518 protected:
00519 TiXmlNode( NodeType type );
00520
00521 #ifdef TIXML_USE_STL
00522
00523 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00524 #endif
00525
00526
00527 TiXmlNode* Identify( const char* start );
00528 void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
00529 target->userData = userData; }
00530
00531
00532 TIXML_STRING SValue() const { return value ; }
00533
00534 TiXmlNode* parent;
00535 NodeType type;
00536
00537 TiXmlNode* firstChild;
00538 TiXmlNode* lastChild;
00539
00540 TIXML_STRING value;
00541
00542 TiXmlNode* prev;
00543 TiXmlNode* next;
00544 void* userData;
00545 };
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 class TiXmlAttribute : public TiXmlBase
00556 {
00557 friend class TiXmlAttributeSet;
00558
00559 public:
00560
00561 TiXmlAttribute()
00562 {
00563 document = 0;
00564 prev = next = 0;
00565 }
00566
00567 #ifdef TIXML_USE_STL
00568
00569 TiXmlAttribute( const std::string& _name, const std::string& _value )
00570 {
00571 name = _name;
00572 value = _value;
00573 document = 0;
00574 prev = next = 0;
00575 }
00576 #endif
00577
00578
00579 TiXmlAttribute( const char * _name, const char * _value )
00580 {
00581 name = _name;
00582 value = _value;
00583 document = 0;
00584 prev = next = 0;
00585 }
00586
00587 const char* Name() const { return name.c_str (); }
00588 const char* Value() const { return value.c_str (); }
00589 const int IntValue() const;
00590 const double DoubleValue() const;
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601 int QueryIntValue( int* value ) const;
00602
00603 int QueryDoubleValue( double* value ) const;
00604
00605 void SetName( const char* _name ) { name = _name; }
00606 void SetValue( const char* _value ) { value = _value; }
00607
00608 void SetIntValue( int value );
00609 void SetDoubleValue( double value );
00610
00611 #ifdef TIXML_USE_STL
00612
00613 void SetName( const std::string& _name )
00614 {
00615 StringToBuffer buf( _name );
00616 SetName ( buf.buffer ? buf.buffer : "error" );
00617 }
00618
00619 void SetValue( const std::string& _value )
00620 {
00621 StringToBuffer buf( _value );
00622 SetValue( buf.buffer ? buf.buffer : "error" );
00623 }
00624 #endif
00625
00626
00627 TiXmlAttribute* Next() const;
00628
00629 TiXmlAttribute* Previous() const;
00630
00631 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00632 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00633 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00634
00635
00636
00637
00638
00639 virtual const char* Parse( const char* p, TiXmlParsingData* data );
00640
00641
00642 virtual void Print( FILE* cfile, int depth ) const;
00643
00644 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00645
00646
00647 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00648
00649 private:
00650 TiXmlDocument* document;
00651 TIXML_STRING name;
00652 TIXML_STRING value;
00653 TiXmlAttribute* prev;
00654 TiXmlAttribute* next;
00655 };
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 class TiXmlAttributeSet
00671 {
00672 public:
00673 TiXmlAttributeSet();
00674 ~TiXmlAttributeSet();
00675
00676 void Add( TiXmlAttribute* attribute );
00677 void Remove( TiXmlAttribute* attribute );
00678
00679 TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00680 TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00681 TiXmlAttribute* Find( const char * name ) const;
00682
00683 private:
00684 TiXmlAttribute sentinel;
00685 };
00686
00687
00688
00689
00690
00691
00692 class TiXmlElement : public TiXmlNode
00693 {
00694 public:
00695
00696 TiXmlElement (const char * in_value);
00697
00698 #ifdef TIXML_USE_STL
00699
00700 TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::ELEMENT )
00701 {
00702 firstChild = lastChild = 0;
00703 value = _value;
00704 }
00705 #endif
00706
00707 virtual ~TiXmlElement();
00708
00709
00710
00711
00712 const char* Attribute( const char* name ) const;
00713
00714
00715
00716
00717
00718
00719
00720 const char* Attribute( const char* name, int* i ) const;
00721
00722
00723
00724
00725
00726
00727
00728 const char* Attribute( const char* name, double* d ) const;
00729
00730
00731
00732
00733
00734
00735
00736
00737 int QueryIntAttribute( const char* name, int* value ) const;
00738
00739 int QueryDoubleAttribute( const char* name, double* value ) const;
00740
00741
00742
00743
00744 void SetAttribute( const char* name, const char * value );
00745
00746 #ifdef TIXML_USE_STL
00747 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00748 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00749
00750
00751 void SetAttribute( const std::string& name, const std::string& _value )
00752 {
00753 StringToBuffer n( name );
00754 StringToBuffer v( _value );
00755 if ( n.buffer && v.buffer )
00756 SetAttribute (n.buffer, v.buffer );
00757 }
00758
00759 void SetAttribute( const std::string& name, int _value )
00760 {
00761 StringToBuffer n( name );
00762 if ( n.buffer )
00763 SetAttribute (n.buffer, _value);
00764 }
00765 #endif
00766
00767
00768
00769
00770 void SetAttribute( const char * name, int value );
00771
00772
00773
00774 void RemoveAttribute( const char * name );
00775 #ifdef TIXML_USE_STL
00776 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00777 #endif
00778
00779 TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00780 TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00781
00782
00783 virtual TiXmlNode* Clone() const;
00784
00785
00786 virtual void Print( FILE* cfile, int depth ) const;
00787
00788 protected:
00789
00790
00791 #ifdef TIXML_USE_STL
00792 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00793 #endif
00794 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00795
00796
00797
00798
00799
00800 virtual const char* Parse( const char* p, TiXmlParsingData* data );
00801
00802
00803
00804
00805
00806 const char* ReadValue( const char* in, TiXmlParsingData* prevData );
00807
00808 private:
00809 TiXmlAttributeSet attributeSet;
00810 };
00811
00812
00813
00814
00815 class TiXmlComment : public TiXmlNode
00816 {
00817 public:
00818
00819 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00820 virtual ~TiXmlComment() {}
00821
00822
00823 virtual TiXmlNode* Clone() const;
00824
00825 virtual void Print( FILE* cfile, int depth ) const;
00826 protected:
00827
00828 #ifdef TIXML_USE_STL
00829 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00830 #endif
00831 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00832
00833
00834
00835
00836 virtual const char* Parse( const char* p, TiXmlParsingData* data );
00837 };
00838
00839
00840
00841
00842 class TiXmlText : public TiXmlNode
00843 {
00844 friend class TiXmlElement;
00845 public:
00846
00847 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00848 {
00849 SetValue( initValue );
00850 }
00851 virtual ~TiXmlText() {}
00852
00853 #ifdef TIXML_USE_STL
00854
00855 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00856 {
00857 SetValue( initValue );
00858 }
00859 #endif
00860
00861
00862 virtual void Print( FILE* cfile, int depth ) const;
00863
00864 protected :
00865
00866 virtual TiXmlNode* Clone() const;
00867 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00868
00869 bool Blank() const;
00870
00871
00872
00873
00874 virtual const char* Parse( const char* p, TiXmlParsingData* data );
00875
00876 #ifdef TIXML_USE_STL
00877 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00878 #endif
00879 };
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895 class TiXmlDeclaration : public TiXmlNode
00896 {
00897 public:
00898
00899 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
00900
00901 #ifdef TIXML_USE_STL
00902
00903 TiXmlDeclaration( const std::string& _version,
00904 const std::string& _encoding,
00905 const std::string& _standalone )
00906 : TiXmlNode( TiXmlNode::DECLARATION )
00907 {
00908 version = _version;
00909 encoding = _encoding;
00910 standalone = _standalone;
00911 }
00912 #endif
00913
00914
00915 TiXmlDeclaration( const char* _version,
00916 const char* _encoding,
00917 const char* _standalone );
00918
00919 virtual ~TiXmlDeclaration() {}
00920
00921
00922 const char * Version() const { return version.c_str (); }
00923
00924 const char * Encoding() const { return encoding.c_str (); }
00925
00926 const char * Standalone() const { return standalone.c_str (); }
00927
00928
00929 virtual TiXmlNode* Clone() const;
00930
00931 virtual void Print( FILE* cfile, int depth ) const;
00932
00933 protected:
00934
00935 #ifdef TIXML_USE_STL
00936 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00937 #endif
00938 virtual void StreamOut ( TIXML_OSTREAM * out) const;
00939
00940
00941
00942
00943 virtual const char* Parse( const char* p, TiXmlParsingData* data );
00944
00945 private:
00946 TIXML_STRING version;
00947 TIXML_STRING encoding;
00948 TIXML_STRING standalone;
00949 };
00950
00951
00952
00953
00954
00955
00956
00957 class TiXmlUnknown : public TiXmlNode
00958 {
00959 public:
00960 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
00961 virtual ~TiXmlUnknown() {}
00962
00963
00964 virtual TiXmlNode* Clone() const;
00965
00966 virtual void Print( FILE* cfile, int depth ) const;
00967 protected:
00968 #ifdef TIXML_USE_STL
00969 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00970 #endif
00971 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00972
00973
00974
00975
00976 virtual const char* Parse( const char* p, TiXmlParsingData* data );
00977 };
00978
00979
00980
00981
00982
00983
00984 class TiXmlDocument : public TiXmlNode
00985 {
00986 public:
00987
00988 TiXmlDocument();
00989
00990 TiXmlDocument( const char * documentName );
00991
00992 #ifdef TIXML_USE_STL
00993
00994 TiXmlDocument( const std::string& documentName ) :
00995 TiXmlNode( TiXmlNode::DOCUMENT )
00996 {
00997 value = documentName;
00998 error = false;
00999 }
01000 #endif
01001
01002 virtual ~TiXmlDocument() {}
01003
01004
01005
01006
01007
01008 bool LoadFile();
01009
01010 bool SaveFile() const;
01011
01012 bool LoadFile( const char * filename );
01013
01014 bool SaveFile( const char * filename ) const;
01015
01016 #ifdef TIXML_USE_STL
01017 bool LoadFile( const std::string& filename )
01018 {
01019 StringToBuffer f( filename );
01020 return ( f.buffer && LoadFile( f.buffer ));
01021 }
01022 bool SaveFile( const std::string& filename ) const
01023 {
01024 StringToBuffer f( filename );
01025 return ( f.buffer && SaveFile( f.buffer ));
01026 }
01027 #endif
01028
01029
01030
01031 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
01032
01033
01034
01035
01036
01037 TiXmlElement* RootElement() const { return FirstChildElement(); }
01038
01039
01040
01041
01042
01043
01044 bool Error() const { return error; }
01045
01046
01047 const char * ErrorDesc() const { return errorDesc.c_str (); }
01048
01049
01050
01051
01052 const int ErrorId() const { return errorId; }
01053
01054
01055
01056
01057
01058
01059
01060
01061 int ErrorRow() { return errorLocation.row+1; }
01062 int ErrorCol() { return errorLocation.col+1; }
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01085
01086 int TabSize() const { return tabsize; }
01087
01088
01089
01090
01091 void ClearError() { error = false;
01092 errorId = 0;
01093 errorDesc = "";
01094 errorLocation.row = errorLocation.col = 0;
01095
01096 }
01097
01098
01099 void Print() const { Print( stdout, 0 ); }
01100
01101
01102 virtual void Print( FILE* cfile, int depth = 0 ) const;
01103
01104 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
01105
01106 protected :
01107 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01108
01109 virtual TiXmlNode* Clone() const;
01110 #ifdef TIXML_USE_STL
01111 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01112 #endif
01113
01114 private:
01115 bool error;
01116 int errorId;
01117 TIXML_STRING errorDesc;
01118 int tabsize;
01119 TiXmlCursor errorLocation;
01120 };
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203 class TiXmlHandle
01204 {
01205 public:
01206
01207 TiXmlHandle( TiXmlNode* node ) { this->node = node; }
01208
01209 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01210
01211
01212 TiXmlHandle FirstChild() const;
01213
01214 TiXmlHandle FirstChild( const char * value ) const;
01215
01216 TiXmlHandle FirstChildElement() const;
01217
01218 TiXmlHandle FirstChildElement( const char * value ) const;
01219
01220
01221
01222
01223 TiXmlHandle Child( const char* value, int index ) const;
01224
01225
01226
01227 TiXmlHandle Child( int index ) const;
01228
01229
01230
01231
01232 TiXmlHandle ChildElement( const char* value, int index ) const;
01233
01234
01235
01236
01237 TiXmlHandle ChildElement( int index ) const;
01238
01239 #ifdef TIXML_USE_STL
01240 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01241 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01242
01243 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01244 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01245 #endif
01246
01247
01248 TiXmlNode* Node() const { return node; }
01249
01250 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01251
01252 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01253
01254 private:
01255 TiXmlNode* node;
01256 };
01257
01258
01259 #endif
01260